import styled from './index.module.css';
import { Tabs, TabsProps, message } from 'antd';
import { OrderStatus } from '@/config/order.config';
import OrderList from './components/orderList';
import { fetchPay } from '@/api/pay';
import { Pay } from '../settlement/type';
import { IResponse } from '@/types';
export default function Order() {
    const onChange = (key: string) => {
        console.log(key);
    };
    const items: TabsProps['items'] = [];
    const goPay = (id: string, totalPrice: number) => {
        fetchPay<Pay, IResponse<string>>({
            orderId: id,
            totalPrice: String(totalPrice),
            returnUrl: window.location.origin + '/order/payRes?orderId=' + id,
        }).then((res) => {
            if (res.statusCode === 200) {
                if (res.data) {
                    window.location.href = res.data;
                }
            } else {
                message.error(res.message);
            }
        });
    };
    OrderStatus.forEach((item, index) => {
        items.push({
            key: String(index + 1),
            label: item,
            children: <OrderList goPay={goPay} key={index} status={index + 1}></OrderList>,
        });
    });

    return (
        <div className={styled.order}>
            <Tabs defaultActiveKey="1" items={items} onChange={onChange} />
        </div>
    );
}
